// HEAD YieldCurve_RateBondAnalysis H
/*==================================================================================================================
                  Copyright (C) 2013 SUMSCOPE L.P.
                  ALL RIGHTS RESERVED 
====================================================================================================================
File description:
    Singleton class to get specific yield curve. UI layer can get specific yield curve points through it.

====================================================================================================================
...Date      Name                                  Description of Change
04-Apr-2013  James Xu                              Initial version
27-Apr-2013  James Xu                              Add GetYieldCurvePoints
07-May-2013  James Xu                              Add overloaded method GetYieldCurvePoints
21-May-2013  James Xu                              Add GetYieldSpreads
24-May-2013  James Xu                              Add GetParCurve
03-Jun-2013  James Xu                              Add GetZeroCurvePoints and GetZeroCurve
$HISTORY$
===================================================================================================================*/

#ifndef YC_RATE_BOND_ANALYSIS_H
#define YC_RATE_BOND_ANALYSIS_H

#include "InterpolatedBondYTMCurve.h"
#include "BondDataStructure.h"
#include <memory>

using namespace std;

namespace YieldCurve
{
    class RateBondAnalysis
    {

    public:
        virtual ~RateBondAnalysis(void);

    public:
        
        //*********************************************************************************************************************************//
        //                                          Par Yield Curve                                                                        //
        //*********************************************************************************************************************************//
        
        // Return a yield curve pointer per given bond data and yield curve type
        // The caller needs to delete the pointer! 
        BondYieldCurve* GetParCurve(
                                    const std::vector<YCInfo>& bondData, 
                                    const int                  yieldDate,         // Input: Date the curve represents. format:yyyymmdd, ie:20130507
                                    YieldCurveType             ycType = GOV_BOND  // Input: Curve type
                                   );
        
        
        // Return a vector of interpolated yield curve points from give quotes
        // 返回值 = 0， 成功; 返回值 != 0, 失败。根据返回值调用ErrorMessage()可以找到相应的错误消息
        int GetYieldCurvePoints(
                                const std::vector<YCInfo>& bondData, 
                                const int                  yieldDate,        // Input: Date the curve represents. format:yyyymmdd, ie:20130507
                                std::vector<double>        samplingMat,      // Input: Sampling vector which contains remaining maturities
                                YieldCurveType             ycType,           // Input: Curve type
                                std::vector<YieldPoints>&  samplingMatYields // Output: Yields vector corresponding to the sampling maturities
                               );

        // Return a vector of interpolated yield curve points
        // 返回值 = 0， 成功; 返回值 != 0, 失败。根据返回值调用ErrorMessage()可以找到相应的错误消息
        int GetYieldCurvePoints(
                                const std::vector<YCInfo>& bondData, 
                                const int                  yieldDate,         // Input: Date the curve represents. format:yyyymmdd, ie:20130507
                                int                        countSamplingPts,  // Input: Number of sampling points
                                YieldCurveType             ycType,            // Input: Curve type
                                std::vector<YieldPoints>&  samplingMatYields  // Output: Yields vector corresponding to the sampling maturities
                               );


        // Return a vector of spreads between source curve and benchmark
        // 返回值 = 0， 成功; 返回值 != 0, 失败。根据返回值调用ErrorMessage()可以找到相应的错误消息
        int GetYieldSpreads(                               
                            const std::vector<YCInfo>& bondDataBHM,            // Input: Benchmark yield curve data
                            YieldCurveType             bhmType,                // Input: Benchmark yield curve type
                            const std::vector<YCInfo>& bondDataSrc,            // Input: Source yield curve data
                            YieldCurveType             srcType,                // Input: Source yield curve type
                            const int                  yieldDate,              // Input: Date the curve represents. format:yyyymmdd, ie:20130507
                            const int                  nSpreadPts,             // Input: Number of spread points
                            std::vector<YieldPoints>&  spreads                 // Output: Spreads vector between source curve and benchmark
                           );


        //*********************************************************************************************************************************//
        //                                          Zero Yield Curve                                                                       //
        //*********************************************************************************************************************************//

        // Return a vector of zero curve points from give quotes
        // 返回值 = 0， 成功; 返回值 != 0, 失败。根据返回值调用ErrorMessage()可以找到相应的错误消息
        int GetZeroCurvePoints(
                               const std::vector<YCInfo>& bondData, 
                               const int                  yieldDate,        // Input: Date the curve represents. format:yyyymmdd, ie:20130507
                               int                        count,            // Input: Number of sampling points
                               std::vector<YieldPoints>&  curvePoints,      // Output: Yields vector
                               YieldCurveType             ycType = GOV_BOND // Input: Curve type
                              );

        // Return a yield curve pointer per given bond data and yield curve type
        // The caller needs to delete the pointer! 
        BondYieldCurve* GetZeroCurve(
                                    const std::vector<YCInfo>& bondData, 
                                    const int                  yieldDate,         // Input: Date the curve represents. format:yyyymmdd, ie:20130507
                                    YieldCurveType             ycType = GOV_BOND  // Input: Curve type
                                   );

        // Statistic functions
        static std::auto_ptr<RateBondAnalysis> GetInstance()
        {
            if (!instance_.get())
            {
                instance_ = std::auto_ptr<RateBondAnalysis>(new RateBondAnalysis());
                return instance_;
            } 
            else
            {
                return instance_;
            }
        }

    private:
        RateBondAnalysis();
        static std::auto_ptr<RateBondAnalysis> instance_; 
    };
}

#endif

